#include <libpub.h>
#include <arch.h>

void DumpAllGPIOs()
{
    printf("Port A:\n");
    printf("    GPACON: 0x%08x\n", rGPACON);
    printf("    GPADAT: 0x%08x\n", rGPADAT);

    printf("Port B:\n");
    printf("    GPBCON: 0x%08x\n", rGPBCON);
    printf("    GPBDAT: 0x%08x\n", rGPBDAT);
    printf("    GPBUP:  0x%08x\n", rGPBUP);

    printf("Port C:\n");
    printf("    GPCCON: 0x%08x\n", rGPCCON);
    printf("    GPCDAT: 0x%08x\n", rGPCDAT);
    printf("    GPCUP:  0x%08x\n", rGPCUP);

    printf("Port D:\n");
    printf("    GPDCON: 0x%08x\n", rGPDCON);
    printf("    GPDDAT: 0x%08x\n", rGPDDAT);
    printf("    GPDUP:  0x%08x\n", rGPDUP);

    printf("Port E:\n");
    printf("    GPECON: 0x%08x\n", rGPECON);
    printf("    GPEDAT: 0x%08x\n", rGPEDAT);
    printf("    GPEUP:  0x%08x\n", rGPEUP);

    printf("Port F:\n");
    printf("    GPFCON: 0x%08x\n", rGPFCON);
    printf("    GPFDAT: 0x%08x\n", rGPFDAT);
    printf("    GPFUP:  0x%08x\n", rGPFUP);

    printf("Port G:\n");
    printf("    GPGCON: 0x%08x\n", rGPGCON);
    printf("    GPGDAT: 0x%08x\n", rGPGDAT);
    printf("    GPGUP:  0x%08x\n", rGPGUP);

    printf("Port H:\n");
    printf("    GPHCON: 0x%08x\n", rGPHCON);
    printf("    GPHDAT: 0x%08x\n", rGPHDAT);
    printf("    GPHUP:  0x%08x\n", rGPHUP);

    printf("Port J:\n");
    printf("    GPJCON: 0x%08x\n", rGPJCON);
    printf("    GPJDAT: 0x%08x\n", rGPJDAT);
    printf("    GPJUP:  0x%08x\n", rGPJUP);

}

//Usage:
//gpio dump
int _Do_Test_Gpio(char *param)
{
    char *sub = NULL;

    TOUT(1, 1, printf("\n_Do_TEST_Gpio(%s)\n", param));

    if(*param){//gpio
        param = Bo_ParseString(param, &sub);
        if (0 == Bo_MatchString(sub, "dump")){ //gpio dump
            TOUT(0, 1, printf("\ngpio dump:"));
            DumpAllGPIOs();

        }
        else{
            TOUT(1, 1, printf("\nWrong Input"));
            return -1;
        }
    }
    else{
        TOUT(1, 1, printf("\nWrong Input"));
        return -1;
    }

    return 0;
}
